package monster.flight.admin.action.xtgl.dict;

import monster.comm.action.BaseJsonAction;
import monster.comm.log.ILog;
import monster.comm.log.LogService;
import monster.comm.util.ReturnConstant;
import monster.flight.admin.manager.service.xtgl.DictService;
import monster.flight.comm.entity.vo.Xt_dict_detail;

/**
 * 
* 创建信息=============
* 类名: monster.flight.admin.action.xtgl.dict.DictDetailSaveAction
* 类作用描述: 保存一条字典明细记录：包括新增、修改
* 创建人： zhongjianjun
* 创建时间： 2013-1-25 上午11:25:17
* 修改信息1=============
* 修改类型:     //1.修改bug 2.业务变化修改
* 修改描述: 
* 修改人：  
* 修改时间：
 */
public class DictDetailSaveAction extends BaseJsonAction{
	private static final long serialVersionUID = 1L;
	private static ILog log = LogService.getLog(DictDetailSaveAction.class);
	private DictService dictService;
	private Xt_dict_detail dict_detail;
	 
	public Xt_dict_detail getDict_detail() {
		return dict_detail;
	}
	public void setDict_detail(Xt_dict_detail dict_detail) {
		this.dict_detail = dict_detail;
	}
	
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}

	/**
	 * 保存数据，包括新增字典明细，和修改字典明细
	 */
	public String save(){
		String islogin = this.isLogin();
		if("0".equals(islogin)){
			returnVO.returnCode=ReturnConstant.IS_NOT_LOGIN;
	    	returnVO.returnDesc="没有登录";
		}
		if("1".equals(islogin)){
			 try {
				 Integer.parseInt(dict_detail.getLevel_seq());// 验证level_seq是否为整数
				 if("0".equals(dict_detail.getOption_sn())){//新增字典明细时 option_sn=0,所以调insert函数
					 dictService.insertDictDetail(dict_detail);
				 } else { //更新
					 dictService.updateDictDetailByKey(dict_detail);
				 }
				 returnVO.returnCode=ReturnConstant.IS_DEAL_OK;
				 returnVO.returnDesc="操作成功";
			}catch(NumberFormatException nfe){
				returnVO.returnCode=ReturnConstant.IS_ERR;
        		returnVO.returnDesc="保存数据字典明细项 时检测到选项顺序不是有效的正整数!";
        		log.error(nfe.getMessage());
			} catch (Exception e) {
				returnVO.returnCode=ReturnConstant.IS_ERR;
        		returnVO.returnDesc="保存数据字典明细项失败!";
        		log.error(e.getMessage());
			}
		}
		return "success";
	}

}
